<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	     <script src="Public/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
	    <script src="Public/Home/bootstrap/js/bootstrap.min.js"></script>
	    <!-- Loading Flat UI -->
	    <link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	</head>
	
	
	<script>
		$(function(){
//			alert(2);
			var cos = $('select[name="combine[]"]');
	        var len = cos.length;
	            cos.change(function(){
	        var gid=$('option::selected').attr('gid');
//	       alert(gid);
		   var data = {
			   'gid' :gid,
			   'combine' : {}
		     };
		     	for (var i = 0; i < len; ++i){
			       if (cos.eq(i).val() == 0){
				   return;
			    }else{
				data.combine[i] = cos.eq(i).val();
			    }
		    }
		       $.ajax({
		    	type:"get",
		    	url:"{{U('check')}}",
		    	data:data,
            	dataType:'json',
            	success:function(data){
//          		alert(data);
				if (data == 0){
					alert('货品已存在，如果要修改库存，请点击修改');
					for (var i = 0; i < len; ++i){
						cos.eq(i).val(0);
					}
				  }
            	}
		    });
		     
	        	
	        })
		})

	</script>
	
	
	<body>
		<table class="table table-hover">
			<tr class="active">
				<td width="80">货品id</td>

				<td width="">颜色</td>
				<td width="">尺码</td>

				<td width="40">库存</td>
				<td width="">货号</td>
				<td width="150">操作</td>
			</tr>
			{{foreach from="$listData" key="$k" value="$v"}}
			<tr>
				<td>{{$v['glid']}}</td>
				<td>{{$v['combine'][0]}}</td>
				<td>{{$v['combine'][1]}}</td>
				<td>{{$v['inventory']}}</td>
				<td>{{$v['number']}}</td>
				<td>
					<a href="{{U('edit',array('gid'=>$v['gid'],'glid'=>$v['glid']))}}" class="btn btn-sm btn-warning">编辑</a>
					<a href="javascript:if(confirm('确认删除吗?')) location.href='{{U('del',array('glid'=>$v['glid'],'gid'=>$v['gid']))}}' ;" class="btn btn-sm btn-danger">删除</a>
				</td>
			</tr>
			{{endforeach}}
			<!--添加货品-->
			
				
				
			<tr>
				<td>添加货品</td>
<form action="" method="post">
				<td width="40">
					<select name="combine[]">
						<option value="">请选择</option>
						{{foreach from="$data" key="$k" value="$v"}}
				        {{if value="$v['taname']=='颜色'"}}
						<option value="{{$v['gtid']}}" {{if value="in_array($v['gtid'],$oldData['combine'])"}} selected {{endif}}>{{$v['gtvalue']}}</option>
						{{endif}}
						{{endforeach}}
					</select>
				</td>
			   
				<td width="40">
					<select name="combine[]">
						<option value="">请选择</option>
						{{foreach from="$data" key="$k" value="$v"}}
				        {{if value="$v['taname']=='尺寸'"}}
						<option value="{{$v['gtid']}}" {{if value="in_array($v['gtid'],$oldData['combine'])"}} selected {{endif}}>{{$v['gtvalue']}}</option>
						{{endif}}
						{{endforeach}}
					</select>
				</td>
				<input type="hidden" name="glid" id="glid" value="{{$glid}}" />
				<input type="hidden" name="gid" id="" value="{{$data[0]['gid']}}" />
				<!--库存-->
				<td width="">
					<input type="text" name="inventory" id="" value="{{$listData[0]['inventory']}}" />
				</td>
				<!--货号-->
				<td width="40">
					<input type="text" name="number" id="" value="{{$listData[0]['number']}}" />
				</td>
				<td>
					<button class="btn btn-sm btn-warning"  type="submit" >确认编辑 </button>
				</td>
			</tr>
			
			</form>
		</table>
	</body>
</html>
